package cn.iocoder.yudao.module.design.dal.mysql.pic;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.design.controller.admin.pic.vo.PicExportReqVO;
import cn.iocoder.yudao.module.design.controller.admin.pic.vo.PicPageReqVO;
import cn.iocoder.yudao.module.design.dal.dataobject.pic.PicDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;

/**
 * 图片 Mapper
 *
 * @author czw
 */
@Mapper
public interface PicMapper extends BaseMapperX<PicDO> {

    default PageResult<PicDO> selectPage(PicPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<PicDO>()
                .eqIfPresent(PicDO::getHouseId, reqVO.getHouseId())
                .eqIfPresent(PicDO::getFlowId, reqVO.getFlowId())
                .eqIfPresent(PicDO::getNodeId, reqVO.getNodeId())
                .eqIfPresent(PicDO::getItemId, reqVO.getItemId())
                .eqIfPresent(PicDO::getUrl, reqVO.getUrl())
                .eqIfPresent(PicDO::getStatus, reqVO.getStatus())
                .eqIfPresent(PicDO::getUploadType, reqVO.getUploadType())
                .eqIfPresent(PicDO::getSourceType, reqVO.getSourceType())
                .orderByAsc(PicDO::getId));
    }

    default List<PicDO> selectList(PicExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<PicDO>()
                .eqIfPresent(PicDO::getHouseId, reqVO.getHouseId())
                .eqIfPresent(PicDO::getFlowId, reqVO.getFlowId())
                .eqIfPresent(PicDO::getNodeId, reqVO.getNodeId())
                .eqIfPresent(PicDO::getItemId, reqVO.getItemId())
                .eqIfPresent(PicDO::getUrl, reqVO.getUrl())
                .eqIfPresent(PicDO::getStatus, reqVO.getStatus())
                .eqIfPresent(PicDO::getUploadType, reqVO.getUploadType())
                .eqIfPresent(PicDO::getSourceType, reqVO.getSourceType())
                .betweenIfPresent(PicDO::getCreateTime, reqVO.getCreateTime())
                .orderByAsc(PicDO::getId));
    }

    /**
     * 查询关联人
     * @param houseIds
     * @return
     */
    List<Map> getPicsByHouseIds(@Param("parentId") String houseIds);

    /**
     * 查询图片和节点信息
     * @param parentId
     * @return
     */
    List<Map> getPicUrlByHouseId(@Param("parentId") String parentId);
}
